<template>
	<view>
		<view class="content wrap1">
			<u-image :showLoading="true" :src="src" width="310px" height="200px"></u-image>
			<u-button type="primary" @click="findMake()">查询已预约情况</u-button>
			<u-form :model="makeInfo" ref="uForm"  :rules="rules">
				<u-form-item label="预约类型*" label-width="150">
					<u-radio-group v-model="makeInfo.makeType">
						<u-radio 
							@change="radioChange" 
							v-for="(item, index) in makeTypelist" :key="index" 
							:name="item.name"
						>
						{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				
				<u-form-item label="月台*" label-width="150" left-icon="grid">
					<u-radio-group v-model="makeInfo.railwayPlatformName">
						<u-radio 
							@change="radioChange1" 
							v-for="(item, index) in railwayPlatformlist" :key="index" 
							:name="item.name"
						>
						{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				
				<u-form-item label="车牌号*" label-width="150" left-icon="car" prop="carNumber"><u-input v-model="makeInfo.carNumber" type="text" disabled="true" placeholder="请输入车牌号"/></u-form-item>
				
				<u-form-item label="车型*" label-width="150" left-icon="car" prop="carType"><u-input v-model="makeInfo.carType" type="text" disabled="true" placeholder="请输入车型"/></u-form-item>
				
				<u-form-item label="姓名*" label-width="150" left-icon="account" prop="driver"><u-input v-model="makeInfo.driver" type="text" disabled="true" placeholder="请输入姓名"/></u-form-item>
				
				<u-form-item label="电话*" label-width="150" left-icon="phone" prop="tel"><u-input v-model="makeInfo.tel" type="text" disabled="true" placeholder="请输入联系电话"/></u-form-item>
				
				<u-form-item label="体积*" label-width="150" prop="volume"><u-input v-model="makeInfo.volume" type="digit" placeholder="请输入体积"/></u-form-item>
				
				<u-form-item label="抵达时间*" label-width="180" left-icon="calendar" prop="arriveTime"><u-input v-model="makeInfo.arriveTime" type="select" placeholder="请选择抵达时间" @click="getT()"/></u-form-item>
				
				<u-form-item label="离开时间*" label-width="180" left-icon="calendar" prop="leaveTime"><u-input v-model="makeInfo.leaveTime" type="select" placeholder="请选择离开时间" @click="getT2()"/></u-form-item>
				
				<u-form-item label="备注" label-width="150"><u-input v-model="makeInfo.notes" type="textarea" placeholder="请输入备注" disabled="true"/></u-form-item>
				
				<u-form-item label="状态*" label-width="150">
					<u-radio-group v-model="makeInfo.state">
						<u-radio 
							@change="radioChange2" 
							v-for="(item, index) in statelist" :key="index" 
							:name="item.name"
						>
						{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				
				<u-form-item label="审核备注*" label-width="150" prop="examineNotes"><u-input v-model="makeInfo.examineNotes" type="textarea" placeholder="请输入审核备注"/></u-form-item>
			</u-form>
			<u-button @click="submit">提交</u-button>
		</view>
		<view>
			<u-picker mode="time" v-model="show" :default-time="endTime" :params="params" @confirm="confirm"></u-picker>
		</view>
		<view>
			<u-picker mode="time" v-model="show2" :default-time="endTime" :params="params" @confirm="confirm2"></u-picker>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				makeInfo:{
					id:"",
					makeType:'',
					railwayPlatformName:"",
					carNumber:"",
					carType:"",
					driver:"",
					tel:"",
					volume:"",
					arriveTime:"",
					leaveTime:"",
					notes:"",
					state:"",
					examineNotes:""
				},
				src:'https://www.56linked.com/images/index1/book/p1.png?v=20211118',
				makeTypelist: [
					{
						name: '提货预约'
					},
					{
						name: '卸货预约'
					}
				],
				statelist: [
					{
						name: '已修改'
					},
					{
						name: '已拒绝'
					}
				],
				railwayPlatformlist:[],
				show:false,
				show2:false,
				endTime:'',
				
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
			    rules: {
					carType: [
						{ 
							required: true,
							message: '请输入车型', 
							trigger: 'blur',
						}
					],
					carNumber: [
						{ 
							required: true,
							message: '请输入车牌号', 
							trigger: 'blur',
						}
					],
					driver: [
						{ 
							required: true,
							message: '请输入司机', 
							trigger: 'blur',
						}
					],
					tel: [
						{ 
							required: true,
							message: '请输入联系电话', 
							trigger: 'blur',
						}
					],
					volume: [
						{ 
							required: true,
							message: '请输入体积', 
							trigger: 'blur',
						},
						{
							type:'number',
							message: '请输入正确的数据类型', 
							trigger: 'blur'
						}
					],
					arriveTime: [
						{ 
							required: true,
							message: '请选择抵达时间', 
							trigger: 'blur',
						}
					],
					leaveTime: [
						{ 
							required: true,
							message: '请选择离开时间', 
							trigger: 'blur',
						}
					],
					examineNotes: [
						{ 
							required: true,
							message: '请输入审核备注', 
							trigger: 'blur',
						}
					],
				}
			}
		},
		onLoad(open) {
			this.$http.post('/rest/railwayPlatform/getById',{
			},{
				params: {id:open.yid},
				header: {
					'Authorization' :uni.getStorageSync('token'),
				}
			}).then(res => {
				if(res.data.data != null){
					this.makeInfo.id = res.data.data.id
					this.makeInfo.makeType = res.data.data.makeType
					this.makeInfo.railwayPlatformName = res.data.data.railwayPlatformName
					this.makeInfo.carType = res.data.data.carType
					this.makeInfo.carNumber = res.data.data.carNumber
					this.makeInfo.driver = res.data.data.driver
					this.makeInfo.tel = res.data.data.tel
					this.makeInfo.volume = res.data.data.volume
					this.makeInfo.arriveTime = res.data.data.arriveTime
					this.makeInfo.leaveTime = res.data.data.leaveTime
					this.makeInfo.notes = res.data.data.notes
					this.makeInfo.state = '已修改'
					this.makeInfo.examineNotes = res.data.data.examineNotes
				}
			})
			
			this.$http.post('/rest/railwayPlatform/getRailwayPlatformList',{
			},{
				params: {},
				header: {
					'Authorization' :uni.getStorageSync('token'),
				}
			}).then(res => {
				for(let item1 of res.data.data) {
					let obj = {}
					obj.name = item1.railwayPlatformName
					this.railwayPlatformlist.push(obj)
				}
			})
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			getT(){
				this.show = true
			},
			getT2(){
				this.show2 = true
			},
			confirm(e) {
				this.makeInfo.arriveTime = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute + ':' + e.second
			},
			confirm2(e) {
				this.makeInfo.leaveTime = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute + ':' + e.second
			},
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
			},
			// 选中某个单选框时，由radio时触发
			radioChange1(e) {
				console.log(e);
			},
			// 选中某个单选框时，由radio时触发
			radioChange2(e) {
				console.log(e);
			},
			submit() {
				let that = this
				this.$refs.uForm.validate(valid => {
					if (valid) {
						console.log('验证通过');
						if(typeof that.makeInfo.railwayPlatformName == 'undefined' || that.makeInfo.railwayPlatformName == null || that.makeInfo.railwayPlatformName == ""){
							uni.showToast({
								title: "未获取到月台",
								icon: 'none'
							})
							return
						}
						uni.showLoading({
							title: '正在提交'
						})
						this.$http.post('/rest/railwayPlatform/editItem',{
						},{
							params: that.makeInfo,
							header: {
								'Authorization' :uni.getStorageSync('token'),
							}
						}).then(res => {
							uni.hideLoading()
							if(res.data.code == 200) {
								this.$refs.uToast.show({
									title: '操作成功',
									type: 'success'
								})
								setTimeout(() => {
									this.$Router.back()
								}, 1000)
							} else {
								this.$refs.uToast.show({
									title: res.data.message,
									type: 'error'
								})
							}
						})
					} else {
						console.log('验证失败');
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
			background-color: #ffffff;
	}
	.wrap {
		padding: 15rpx;
	}
	.wrap1 {
		padding: 30rpx;
	}
	.weikaishi2{
		font-size: 36rpx;
	}
	.weikaishi3{
		font-size: 32rpx;
	}
	.huanhang{
		word-break:break-all;
	}
</style>
